﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Ecreate.Business;
using Ecreate.Model;
namespace Ecreate.Web.systemanage.info
{
    public partial class infocrud : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                string action = this.Request.QueryString["action"];
                if (!String.IsNullOrEmpty(action))
                {
                    this.hid_action.Value = action;
                    if ("edit".Equals(action))
                    {
                        try
                        {
                            string id = this.Request.QueryString["id"];
                            this.hid_id.Value = id;
                            InfoDtlService service = new InfoDtlService();
                            WebResult<t_info_dtl> result = service.getInfoByID(int.Parse(id));
                            this.txt_keyname.Text = result.ResultObject.Keyname;
                            this.txt_keyvalue.Text = result.ResultObject.Keyvalue;
                            if (result.ResultObject.Fvisible == 1)
                            {
                                this.cb_visible.Checked = true;
                            }
                            else
                            {
                                this.cb_visible.Checked = false;
                            }
                            this.txt_forder.Text = result.ResultObject.Forder.ToString();
                        }
                        catch
                        {



                        }
                    }
                    if ("insert".Equals(action))
                    {



                    }

                    if ("delete".Equals(action))
                    {



                    }
                }
            }
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            InfoDtlService service = new InfoDtlService();
            WebResult<t_info_dtl> result = new WebResult<t_info_dtl>();
           
            if (this.hid_action.Value == "insert")
            {
                result.ResultObject.Keyname = this.txt_keyname.Text;
                result.ResultObject.Keyvalue = this.txt_keyvalue.Text;
                if (this.cb_visible.Checked)
                {

                    result.ResultObject.Fvisible = 1;
                }
                else
                {

                    result.ResultObject.Fvisible = 0;
                }
                try
                {

                    int order = int.Parse(this.txt_forder.Text);
                    result.ResultObject.Forder = order;
                }
                catch
                {
                    return;
                }
                result=service.Insert(result.ResultObject);
                this.lbl_message.Text = result.Message;
                this.lbl_message.Visible = true;

            }
            if (this.hid_action.Value == "edit")
            {

                result.ResultObject.Keyname = this.txt_keyname.Text;
                result.ResultObject.Keyvalue = this.txt_keyvalue.Text;
                if (this.cb_visible.Checked)
                {

                    result.ResultObject.Fvisible = 1;
                }
                else
                {

                    result.ResultObject.Fvisible = 0;
                }
                try
                {

                    int order = int.Parse(this.txt_forder.Text);
                    result.ResultObject.Forder = order;
                }
                catch
                {
                    return;
                }
                result.ResultObject.Dtlid = int.Parse(this.hid_id.Value);
                result = service.Update(result.ResultObject);
                this.lbl_message.Text = result.Message;
                this.lbl_message.Visible = true;
            }
        }
    }
}
